package com.aibaixun.common.utils;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class LocalDateTimeUtils {

    /**
     * 根据两个时间段获取中间所有的日期正序
     * @param startDate
     * @param endDate
     * @return
     */
    public static List<LocalDate> getAscDateList(LocalDate startDate, LocalDate endDate) {
        long size = endDate.toEpochDay() - startDate.toEpochDay();
        if (size < 0) {
            return Collections.emptyList();
        }
        // 初始化大小防止list频繁扩容
        List<LocalDate> result = new ArrayList<>((int)size);
        for (int i = 0; i <= size ; i ++) {
            result.add(startDate);
            startDate = startDate.plusDays(1);
        }
        return result;
    }

    /**
     * 根据两个时间段获取中间所有的日期倒叙
     * @param startDate
     * @param endDate
     * @return
     */
    public  List<LocalDate>  getDescDateList(LocalDate startDate,LocalDate endDate) {
        long size = endDate.toEpochDay() - startDate.toEpochDay();
        if (size < 0) {
            return Collections.emptyList();
        }
        // 初始化大小防止list频繁扩容
        List<LocalDate> result = new ArrayList<>((int)size);
        for (int i = 0; i <= size ; i ++) {
            result.add(endDate);
            endDate = endDate.plusDays(-1);
        }
        return result;
    }

}
